<template>
  <div>
    <!-- 面包屑   -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/layout' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item><a>用户管理</a></el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片    -->
    <el-card class="box-card">
      <el-form label-width="80px">
        <el-form-item label="用户名">
          <el-input v-model="user.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="user.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">立即创建</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { adddUser } from '@/api';
export default {
  data() {
    return {
      user: { username: '', password: '' },
    };
  },
  methods: {
    async onSubmit() {
      if (this.user.username.length > 6 && this.user.password.length > 6) {
        const res = await adddUser(this.user);
        if (res.data.code === 1) {
          this.user = { username: '', password: '' };
          this.$message.success(res.data.msg);
        } else {
          this.$message.warning(res.data.msg);
        }
      } else {
        this.$message.warning('新增用户名或密码最少六位');
      }
    },
  },
};
</script>

<style lang="less" scoped>
.el-card {
  margin-top: 20px;
}
</style>
